﻿using Furion.DatabaseAccessor;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Htx.Fur.Core.Extensions
{
    public static class FurionExtensions
    {
        private const string FakeDeleteColumnName = "IsDeleted";
        /// <summary>
        /// 软删除实体对象，对象需存在IsDeleted属性
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="repository"></param>
        /// <param name="entity"></param>
        public static void FakeDelete<TEntity> (this IPrivateRepository<TEntity> repository, TEntity entity) where TEntity: class, IPrivateEntity, new()
        {
            entity.SetPropertyValue(FakeDeleteColumnName, true);
            repository.UpdateIncludeNow(entity, new[] { FakeDeleteColumnName });
        }

        /// <summary>
        /// 软删除实体对象，对象需存在IsDeleted属性
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="repository"></param>
        /// <param name="id"></param>
        public static void FakeDelete<TEntity>(this IPrivateRepository<TEntity> repository, int id) where TEntity : class, IPrivateEntity, new()
        {
            var entity = new TEntity();
            entity.SetPropertyValue("Id", id);
            repository.FakeDelete(entity);
        }
    }
}
